home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / mtools-3.000 / mtools-3 / mtools-3.0 / file_read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  630 b   |  38 lines

  1. #include "sysincludes.h"
  2. #include "msdos.h"
  3. #include "mtools.h"
  4. #include "file.h"
  5.  
  6. /*
  7.  * Read the clusters given the beginning FAT entry.  Returns 0 on success.
  8.  */
  9.  
  10. int file_read(FILE *fp, Stream_t *Source, int textmode, int stripmode)
  11. {
  12.     char buffer[16384];
  13.     int pos;
  14.     int ret;
  15.  
  16.     if (!Source){
  17.         fprintf(stderr,"Couldn't open source file\n");
  18.         return -1;
  19.     }
  20.     
  21.     pos = 0;
  22.     while(1){
  23.         ret = Source->Class->read(Source, buffer, pos, 16384);
  24.         if (ret < 0 ){
  25.             perror("file read");
  26.             return -1;
  27.         }
  28.         if ( ret == 0)
  29.             break;
  30.         if(!fwrite(buffer, 1, ret, fp)){
  31.             perror("write");
  32.             return -1;
  33.         }
  34.         pos += ret;
  35.     }
  36.     return 0;
  37. }
  38.